home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15071 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  52 lines

  1. Path: EU.net!sun4nl!xs4all!falstaff
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: H E L P
  5. Date: 3 Apr 1996 14:42:25 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4ju2oh$pli@news.xs4all.nl>
  8. References: <N.040296.013047.18@DynamicPPP-185.HIP.CAM.ORG>
  9. NNTP-Posting-Host: xs1.xs4all.nl
  10. X-Newsreader: NN version 6.5.0 #666 (NOV)
  11.  
  12. ramrod@cam.org writes:
  13.  
  14. >Could anyone please tell me how to write the following program.
  15. >Using nested looping, the output is supposed to look like this.
  16.  
  17. >Please enter your age in years (0 to end the program): 10
  18. >Happy Birthday To You
  19. >You are 10 Years Old
  20.  
  21. >\x01\x01\x01\x01\x01\x01\x0\x01\x01\x01(ten happy faces)
  22.  
  23. >The part that I am having a hard time with is the part that
  24. >whatever number I enter for the age, I'm supposed to get the same number
  25. >of happy faces, automatically.  For example If I say I am 45 years old,
  26. >then the program should show 45 happy faces.
  27.  
  28. int main()
  29. {  int i,n;
  30.  
  31.    printf("How old are you: ");
  32.    fflush(stdout);            /* make sure prompt is displayed */
  33.    scanf("%d",&n);            /* get a number                  */
  34.  
  35.    if(n<1 || n>75)            /* added this test as a bonus    */
  36.    {  printf("No you're not!\n");
  37.       return 1; }            /* return with error=1           */
  38.  
  39.    printf("Hurray, %d years old today!\n\n",n);
  40.  
  41.    for(i=0;i<n;i++)            /* now print the faces           */
  42.       putchar('\x01');
  43.  
  44.    return 0;                /* return to OS without error    */
  45. }
  46.  
  47. Falstaff
  48. --
  49. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  50. ------------------------------------------------------------------------
  51. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  52.